package com.eportal.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.eportal.domain.Sysopt;

public class LogoutFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpSession session = req.getSession();
        Sysopt user = (Sysopt)session.getAttribute("user");
        HttpServletResponse resp = (HttpServletResponse) response;
    	if(user!=null&&(user.getrLevel()==4||user.getrLevel()==3)){
    		resp.sendRedirect(AuthenticationFilter.LOGIN_URL_LOCK);//锁厂的终端客户，退出时跳到锁厂登录页	
    	}else{
    		resp.sendRedirect(AuthenticationFilter.LOGIN_URL_COMMUNITY);
    	}
        if (user instanceof Sysopt) {
            session.removeAttribute("user");
            session.invalidate();
        }

        return;
    }

    @Override
    public void destroy() {

    }
}
